package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.MicrobialBiomass;
import com.ruoyi.system.service.IMicrobialBiomassService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 微生物生物量Controller
 * 
 * @author ruoyi
 * @date 2024-03-20
 */
@Controller
@RequestMapping("/system/biomass")
public class MicrobialBiomassController extends BaseController
{
    private String prefix = "system/biomass";

    @Autowired
    private IMicrobialBiomassService microbialBiomassService;

    @RequiresPermissions("system:biomass:view")
    @GetMapping()
    public String biomass()
    {
        return prefix + "/biomass";
    }

    /**
     * 查询微生物生物量列表
     */
    @RequiresPermissions("system:biomass:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MicrobialBiomass microbialBiomass)
    {
        startPage();
        List<MicrobialBiomass> list = microbialBiomassService.selectMicrobialBiomassList(microbialBiomass);
        return getDataTable(list);
    }

    /**
     * 导出微生物生物量列表
     */
    @RequiresPermissions("system:biomass:export")
    @Log(title = "微生物生物量", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MicrobialBiomass microbialBiomass)
    {
        List<MicrobialBiomass> list = microbialBiomassService.selectMicrobialBiomassList(microbialBiomass);
        ExcelUtil<MicrobialBiomass> util = new ExcelUtil<MicrobialBiomass>(MicrobialBiomass.class);
        return util.exportExcel(list, "微生物生物量数据");
    }

    /**
     * 新增微生物生物量
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存微生物生物量
     */
    @RequiresPermissions("system:biomass:add")
    @Log(title = "微生物生物量", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MicrobialBiomass microbialBiomass)
    {
        return toAjax(microbialBiomassService.insertMicrobialBiomass(microbialBiomass));
    }

    /**
     * 修改微生物生物量
     */
    @RequiresPermissions("system:biomass:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        MicrobialBiomass microbialBiomass = microbialBiomassService.selectMicrobialBiomassById(id);
        mmap.put("microbialBiomass", microbialBiomass);
        return prefix + "/edit";
    }

    /**
     * 修改保存微生物生物量
     */
    @RequiresPermissions("system:biomass:edit")
    @Log(title = "微生物生物量", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MicrobialBiomass microbialBiomass)
    {
        return toAjax(microbialBiomassService.updateMicrobialBiomass(microbialBiomass));
    }

    /**
     * 删除微生物生物量
     */
    @RequiresPermissions("system:biomass:remove")
    @Log(title = "微生物生物量", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(microbialBiomassService.deleteMicrobialBiomassByIds(ids));
    }
}
